<script lang="ts" setup>
import type { SystemLoginLogApi } from '#/api/system/loginLog';

import { ref } from 'vue';

import { useVbenModal } from '@vben/common-ui';

import CustomDescriptions from '#/components/descriptions/CustomDescriptions.vue';

import { useDetailSchema } from '../data';

const formData = ref<SystemLoginLogApi.LoginLog>();

const [Modal, modalApi] = useVbenModal({
  async onOpenChange(isOpen: boolean) {
    if (!isOpen) {
      formData.value = undefined;
      return;
    }
    // 加载数据
    const data = modalApi.getData<SystemLoginLogApi.LoginLog>();
    if (!data || !data.id) {
      return;
    }
    modalApi.lock();
    try {
      formData.value = data;
    } finally {
      modalApi.unlock();
    }
  },
});
</script>

<template>
  <Modal
    title="登录日志详情"
    class="w-1/2"
    :show-cancel-button="false"
    :show-confirm-button="false"
  >
    <CustomDescriptions
      :schema="useDetailSchema()"
      :data="formData || {}"
      :column="1"
      empty-text="暂无数据"
    >
      <!-- <template #action="{ data }">
        <div style="font-weight: 500; color: #409eff">
          {{ data.action }}
        </div>
      </template> -->
    </CustomDescriptions>
  </Modal>
</template>
